package com.sk.principle.component;

import com.sk.principle.model.Dog;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BeanLifeComponent implements BeanNameAware {
    private Dog singleton;

    /**
     * 实例化
     */
    public BeanLifeComponent() {
        System.out.println("执行构造函数----------");
    }

    /**
     * 属性赋值
     */
    @Autowired
    public void setSingleton(Dog singleton) {
        this.singleton = singleton;
        System.out.println("执行setSingleton----------");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("setBeanName: "+name);

    }
    @PostConstruct
    public void init(){
        System.out.println("执行init----------");
    }
    public void use(){
        System.out.println("执行use方法----------");
    }
    @PreDestroy
    public void destroy() {
        System.out.println("执行destroy方法----------");
    }
}
